/*
 * Copyright (c) 2016 www.smarthome.com All rights reserved. 本软件源代码版权归----所有,未经许可不得任意复制与传播.
 */
package com.smarthome.base.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.smarthome.base.dao.ShOrdersDao;
import com.smarthome.base.dao.base.BaseDao;
import com.smarthome.base.service.ShOrdersService;
import com.smarthome.base.service.base.BaseServiceImpl;
import com.smarthome.domain.bean.ShOrders;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * ShOrdersService 实现类
 * @author Kongxiangyu
 * @since 2016-03-20
 */
@Service("shOrdersService")
public class ShOrdersServiceImpl extends BaseServiceImpl<ShOrders, Long> implements ShOrdersService {

    @Resource
    private ShOrdersDao shOrdersDao;

    public BaseDao<ShOrders, Long> getDao() {
        return shOrdersDao;
    }

    
    /**
     * 查询工单信息---翻页
     */
    @Override
    public DataGrid queryShOrdersPage(ShOrders shOrders, PageHelper page) {
		DataGrid dataGrid = new DataGrid();
        if (!StringUtils.isBlank(page.getSort())) {
        	shOrders.setOrderField(page.getSort());
        }
        if (!StringUtils.isBlank(page.getOrder())) {
        	shOrders.setOrderFieldType(page.getOrder());
        }
        //
        long totalCount = shOrdersDao.queryShOrderCount(shOrders);
        dataGrid.setTotal(totalCount);
        int startIndex = (page.getPage() - 1) * page.getRows();
        int endIndex = page.getPage() * page.getRows();
        if (totalCount > 0 && totalCount > startIndex) {
        	shOrders.setStartIndex(startIndex);
        	shOrders.setEndIndex(endIndex);
            List<ShOrders> shOrdersList = shOrdersDao.queryShOrdersListPage(shOrders);
            dataGrid.setRows(shOrdersList);
        }
        return dataGrid;
	}
    
    /**
     * 更新
     */
    @Override
	public int batchUpdate(ShOrders shOrders) {
		return shOrdersDao.batchUpdate(shOrders);
	}

    /**
     * 未实现
     */
	@Override
	public ShOrders getDetailById(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 得到订单list
	 */
	@Override
	public List<ShOrders> getShOrdersList(ShOrders shOrders) {
		List<ShOrders> shOrdersList = shOrdersDao.queryShOrdersList(shOrders);
		return shOrdersList;
	}
	
	
	/**
	 * 多表查询--工单信息
	 */
	@Override
	public List<ShOrders> getSendCourierDetailList(ShOrders shOrders) {
		
		return null;
	}


	@Override
	public Integer getSendCourierCount(ShOrders shOrders) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public Map<String, Object> getCountAll(ShOrders shOrders) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> getPicCount(ShOrders shOrders) {
		// TODO Auto-generated method stub
		return null;
	}
}